using UnityEngine;
using System.Collections;

public class RotatingObject: LinkableObject {
	public bool continousRotation=false;
	public bool clockwise=true;
	public float targetAngle=90.0f;
	// Use this for initialization
	private bool rotating=false;
	
	
	public override void reactToTrigger(TriggeredEvent TE)
	{
		rotating=TE.hasMetGoal;
	}
	
	// Update is called once per frame
	public override void Update ()
	{
		base.Update();
		if(rotating)
		{
			if(transform.eulerAngles.z<=targetAngle||continousRotation)
			{
				transform.Rotate(new Vector3(0,0,1),90*Time.deltaTime);
			}
			else
			{
				transform.Rotate(new Vector3(0,0,1),targetAngle-transform.eulerAngles.z);
				rotating=false;
			}
		}
	}
	
	protected override void triggerResponse(TriggeredEvent TE)
	{
		partner.reactToTrigger(TE);
	}
}
